package com.macro.mall.controller.show;

import com.macro.mall.annotation.ShowAccountId;
import com.macro.mall.common.api.ReturnObject;
import com.macro.mall.dto.ShowLoginInfoResp;
import com.macro.mall.dto.UpdateInfoReq;
import com.macro.mall.dto.WxPhoneLoginReq;
import com.macro.mall.service.LoginService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * MinIO对象存储管理Controller
 * Created by macro on 2019/12/25.
 */
@RestController
@Api(tags = "ShowLoginController")
@Tag(name = "ShowLoginController", description = "前台登录控制层")
@RequestMapping("/show/userInfo")
public class UserInfoController {

    @Resource
    private LoginService loginService;

    @ApiOperation("手机号登录")
    @PostMapping(value = "/phone")
    public ReturnObject<String> upload(@Valid @RequestBody WxPhoneLoginReq req) {
       return new ReturnObject<>(loginService.phoneLogin(req));
    }

    @ApiOperation("获取用户基础信息 如果返回的data为null 需要把 TOKEN清空掉让用户去登录")
    @PostMapping(value = "/info")
    @ShowAccountId
    public ReturnObject<ShowLoginInfoResp> info(Long accountId) {
        return new ReturnObject<>(loginService.info(accountId));
    }

    @ApiOperation("更新用户头像和名称")
    @PostMapping(value = "/updateInfo")
    @ShowAccountId
    public ReturnObject<Void> updateInfo(Long accountId, @RequestBody UpdateInfoReq req) {
        loginService.updateInfo(accountId, req);
        return new ReturnObject<>();
    }
}
